package hu.uszeged.inf.wlab.stunner.application;

import hu.uszeged.inf.wlab.stunner.R;

import java.lang.Thread.UncaughtExceptionHandler;

import android.app.Application;

import com.google.analytics.tracking.android.ExceptionReporter;
import com.google.analytics.tracking.android.GAServiceManager;
import com.google.analytics.tracking.android.GoogleAnalytics;
import com.google.analytics.tracking.android.Tracker;

/**
 * @author rakz
 */
public class StunApplication extends Application {

	/** Analytics tracker. */
	private static Tracker mGaTracker;

	/** Analytics instance. */
	private static GoogleAnalytics mGaInstance;

	@Override
	public void onCreate() {
		super.onCreate();
		// Get the GoogleAnalytics singleton. Note that the SDK uses
		// the application context to avoid leaking the current context
		mGaInstance = GoogleAnalytics.getInstance(this);
		// Use the GoogleAnalytics singleton to get a Tracker.
		mGaTracker = mGaInstance.getTracker(this.getResources().getString(R.string.ga_trackingId));
		// EasyTracker.getInstance().setContext(this);

		final UncaughtExceptionHandler myHandler = new ExceptionReporter(
				mGaTracker, // Currently used Tracker.
				GAServiceManager.getInstance(), // GAServiceManager singleton.
				Thread.getDefaultUncaughtExceptionHandler(), this); // Current default uncaught exception handler.

		// Make myHandler the new default uncaught exception handler.
		Thread.setDefaultUncaughtExceptionHandler(myHandler);

		((ExceptionReporter) myHandler).setExceptionParser(new GAExceptionReporter());
	}

}
